<template>
    <el-dialog
            :visible.sync="newFolderDialogVisible"
            title="文件夹命名"
            width="30%"
            @close="reset"
            :close-on-click-modal="false"
            v-dialogDrag>
        <el-form :rules="rules" ref="Form" :model="Form">
            <el-form-item prop="fileName">
                <el-input v-model="Form.fileName" placeholder="请输入文件名"></el-input>
            </el-form-item>
        </el-form>
        <div style="margin-top: 20px;text-align: center">
            <el-button type="primary" @click="submit">确定</el-button>
            <el-button @click="newFolderDialogVisible=false">取消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import axios from 'axios';

    export default {
        name: "newFolderDialog",
        props: ['currentPath'],
        data() {
            return {
                Form: {
                    fileName: '',
                },
                newFolderDialogVisible: false,
                rules: {
                    fileName: [{required: true, message: '请输入文件夹名称', trigger: 'blur'}],
                },
            }
        },
        methods: {
            submit() {
                // console.log(this.currentPath);
                let that = this;
                this.$refs["Form"].validate((valid) => {
                    if (valid) {
                        var url = "http://localhost:9000/dbfg/userself/newfile?path="
                        let path = this.currentPath + "/" + this.Form.fileName;
                        axios.get(url + path)
                            .then(function (res) {
                                if (res.data.code == 200) {
                                    that.$message({
                                        message: '新建文件夹成功',
                                        type: 'success'
                                    });
                                    that.newFolderDialogVisible = false;
                                    that.$emit('refreshCurrentTable');
                                } else {
                                    that.$message({
                                        message: '新建文件夹失败，请重试',
                                        type: 'warning'
                                    });
                                }
                            }).catch(function (error) {
                            console.log(error)
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                })
            },
            reset() {
                // this.Form.fileName='';
                this.$refs["Form"].resetFields();
            }
        },
        created() {
            let that = this;
            this.$Bus.$on("newFolderDialogVisible", res => {
                that.newFolderDialogVisible = res.visible;

            })

        },
    }
</script>

<style>

</style>